// 抽样数量，不合格数量 失焦
function updateConformityQuantity() {
    //更新合格数量
    var unqualifiedQuantity = $("[name=unqualifiedQuantity]").val();
    var samplingQuantity = $("[name=samplingQuantity]").val();
    $("[name=conformityQuantity]").val(samplingQuantity - unqualifiedQuantity);
    //更新不良率
    var rejectRation = (unqualifiedQuantity / samplingQuantity * 100).toFixed(2);
    $("[name=rejectRation]").val(rejectRation + "%");

}

// 重载检验项目
function testReload3(checkScenarioName) {
    layui.use('table', function () {
        var table = layui.table;
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    where: {
                        checkScenarioName: checkScenarioName
                    }
                }, 'data');
            }
        };
        var type = "reload";
        active[type] ? active[type].call(this) : '';
    })
}

//根据 checkProjectKey 查询 检验方案集合名称
function getInspectionPlanMgt(checkScenarioName) {
    var sampleKey = '';
    $.ajax({
        type: "GET",
        url: "/3nod_web/inspectionPlanMgt/getInspectionPlanMgt",
        data: "checkScenarioName=" + checkScenarioName,
        async: false,
        success: function (data) {
            if (data.code == 500) {
                alert(data.msg)
            } else {
                sampleKey = data.data.sampleKey;
            }
        }
    });
    return sampleKey;
}

//方法区
/**
 * 提交的时候自动填充
 */
function submitFill() {
    //保存的时候自动填充拒收数量等值
    $.get("/3nod_web/iqcDetectionDetail/fill", "sku=" + sku + "&receiptKey=" + receiptKey, function (data) {
        if (data == '请求超时，请点击左侧菜单，重新载入!') {
            layer.alert(data);
            return false;
        }
        $("[name=unqualifiedQuantity]").val(data.unqualifiedQuantity);//不合格数量
        $("[name=quarantineQuantity]").val(data.quarantineQuantity); //待检数量
        $("[name=sampleQuantity]").val(data.sampleQuantity);//留样数量
        $("[name=rejectionQuantity]").val(data.rejectionQuantity); //拒收数量
        //验退数量
        $("[name=checkBackQuantity]").val(parseFloat($("[name=sampleQuantity]").val()) + parseFloat($("[name=rejectionQuantity]").val()));
        //入库数量
        $("[name=inventoryQuantity]").val($("[name=quarantineQuantity]").val() - $("[name=rejectionQuantity]").val() - $("[name=sampleQuantity]").val());
        //更新合格数量
        var unqualifiedQuantity = $("[name=unqualifiedQuantity]").val();
        var samplingQuantity = $("[name=samplingQuantity]").val();
        $("[name=conformityQuantity]").val(samplingQuantity - unqualifiedQuantity);
        //更新不良率
        var rejectRation = (unqualifiedQuantity / samplingQuantity * 100).toFixed(2);
        $("[name=rejectRation]").val(rejectRation + "%");
        return true;
    });
    //保存的时候判断检验结果
    $.get("/3nod_web/iqcCheckItemDetails/getCheckResult", "sku=" + sku + "&receiptKey=" + receiptKey, function (data) {
        if (data == '请求超时，请点击左侧菜单，重新载入!') {
            layer.alert(data);
            return false;
        }
        if (data == '合格') {
            $('#decideWay1').css('display', 'none');
            $('#decideWay2').css('display', 'block');
        } else {
            $('#decideWay1').css('display', 'block');
            $('#decideWay2').css('display', 'none');
        }
        //改变检验结果的值
        $("[name=checkResult]").val(data);
    });
}

function checkItemSave() {
    //保存的时候判断检验结果
    $.get("/3nod_web/iqcCheckItemDetails/getCheckResult", "sku=" + sku + "&receiptKey=" + receiptKey, function (data) {
        if (data == '请求超时，请点击左侧菜单，重新载入!') {
            layer.alert(data);
            return false;
        }
        if (data == '合格') {
            $('#decideWay1').css('display', 'none');
            $('#decideWay2').css('display', 'block');
        } else {
            $('#decideWay1').css('display', 'block');
            $('#decideWay2').css('display', 'none');
        }
        //改变检验结果的值
        $("[name=checkResult]").val(data);
    });

};
// 已质检、未填写检验项目 提交修改检验项目已填写
function checkItemOver(data) {
    $.ajax({
        url: '/3nod_web/iqcDetection/submitCheckItem',
        type: 'POST',
        contentType: 'application/json; charset=UTF-8',
        async: false,
        dataType: 'json',
        data: JSON.stringify(data.field),
        success: function (data) {
            if (data == '请求超时，请点击左侧菜单，重新载入!') {
                layer.alert(data);
                return false;
            }
            if (data.code == 500) {
                //layer.alert("提交失败");
                alert(data.msg)
            } else {
                alert("提交成功");
                submitFlag = true;
                var library = $("#library").val();
                var users = $("#users").val();
                $.get("/3nod_web/iqcDetection/setReturnFlag?flag=1");
                location.href = '/3nod_web/iqc/iqcManager?library=' + library + "&users=" + users;

            }

        }
    });
}